package cn.javacc.nav.service;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.javacc.nav.dao.LinkDao;
import cn.javacc.nav.domain.Link;
import cn.javacc.util.Status;

@Service
public class LinkService {
	@Inject
	private LinkDao linkDao;

	public Link getLinkById(Long id) {
		Link link = this.linkDao.get(id);
		if (link != null && link.getStatus() == Status.NORMAL) {
			return link;
		}
		return null;
	}

	public List<Link> listLinks(int offset, int fetchSize) {
		return this.linkDao.findAll(offset, fetchSize);
	}

	public int getLinkTotalSize() {
		return this.linkDao.getTotalSize();
	}

	@Transactional
	public void saveLink(Link link) {
		this.linkDao.save(link);
	}

	@Transactional
	public void updateLink(Link link) {
		this.linkDao.update(link);
	}

	@Transactional
	public void deleteLink(Long id) {
		this.linkDao.delete(id);
	}
}
